#include <cstdio>
#include <memory.h>
#include <algorithm>

using namespace std;

struct Point
{
    int x, y;
};

bool operator < ( const Point &a, const Point &b )
{
    if ( a.x < b.x )
        return true;
    if ( a.x > b.x )
        return false;
    return a.y < b.y;
};

int n, maxp[ 20011 ], minp[ 20011 ];
Point p[ 1011 ];

void init( )
{
    int i;
    memset( maxp, -10000, sizeof( maxp ) );
    memset( minp, 10000, sizeof( minp ) );
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
        scanf("%d%d", &p[ i ].x, &p[ i ].y);
    sort( p, p + n );
    for ( i = 0; i < n; i++ )
    {
        if ( maxp[ p[ i ].x + 10000 ] < i )
            maxp[ p[ i ].x + 10000 ] = i;
        if ( minp[ p[ i ].x + 10000 ] > i )
            minp[ p[ i ].x + 10000 ] = i;
    }
}

bool check( int left, int right, int s )
{
    int mid;
    while ( left <= right )
    {
        mid = ( left + right ) / 2;
        if ( p[ mid ].y == s )
            return true;
        if ( p[ mid ].y < s )
            left = mid + 1;
        else
            right = mid - 1;
    }
    return false;
}

void work( )
{
    int cnt = 0, i, j;
    for ( i = 0; i < n; i++ )
        for ( j = i + 1; j < n; j++ )
        {
            if ( p[ j ].x - p[ i ].x != p[ j ].y - p[ i ].y || p[ j ].y <= p[ i ].y )
                continue;
            if ( check( i + 1, maxp[ p[ i ].x + 10000 ], p[ j ].y ) && check( minp[ p[ j ].x + 10000 ], j - 1, p[ i ].y ) )
                cnt++;
        }
    printf("%d\n", cnt);
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        work( );
    }
    return 0;
}
